$(function () {
    $("#topbtn").click(setTop);
    $("#wonderfulbtn").click(setWonderful);
    $("#deletebtn").click(setDelete);
});
function like(btn,entityType,entityId,userLikeId,postId) {
    $.post(
       "/like",
        {"entityType":entityType,"entityId":entityId,"userLikeId":userLikeId,"postId":postId},
        function (data) {
            var data = $.parseJSON(data);
            //如果code等于0表示点赞成功
            if (data.code == 0){
                $(btn).children("i").text(data.likeCount);
                $(btn).children("b").text(data.likeStatus==0?"赞":"已赞");
            }else {
                alert(data.msg);
            }
        }
    );
}
function setTop() {
    $.post(
        "/discuss/top",
        {"id":$("#postId").val()},
        function (data) {
            data = $.parseJSON(data);
            if (data.code == 1){
                $("#topbtn").attr("disabled","disabled");
            }else {
                alert(data.msg);
            }
        }
    );
}
function setWonderful() {
    $.post(
        "/discuss/wonderful",
        {"id":$("#postId").val()},
        function (data) {
            data = $.parseJSON(data);
            if (data.code == 0){
                $("#wonderfulbtn").attr("disabled","disabled");
            }else {
                alert(data.msg);
            }
        }
    );
}
function setDelete(){
    $.post(
        "/discuss/deleteDis",
        {"id":$("#postId").val()},
        function (data) {
            data = $.parseJSON(data);
            alert(data);
            if (data.code==0){
                window.location.href="/discuss/findDis";
            }else {
                alert(data.msg);
            }
        }
    );
}